<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/8/18 0018
 * Time: 下午 3:11
 */

namespace common\libs;


use Yii;
use yii\helpers\Json;

class Logger
{
	/**
	 * 开发环境或者正式环境都会有的运行时的日志
	 * @param $message
	 * @param string $desc
	 * @param string $category
	 */
	public static function info($message,$desc='',$category = 'runtime')
	{
		$message = is_array($message) ? Json::encode($message) : $message;
		$message = $desc ? $desc.'：'.$message : $message;
		Yii::info($message,$category);
	}
	
	/**
	 * 错误的日志
	 * @param $message
	 * @param string $desc
	 * @param string $category
	 */
	public static function error($message,$desc='',$category = 'error')
	{
		$message = is_array($message) ? Json::encode($message) : $message;
		$message = $desc ? $desc.'：'.$message : $message;
		Yii::error($message,$category);
	}
	
	/**
	 * 报错的日志
	 * @param $message
	 * @param string $desc
	 * @param string $category
	 */
	public static function warning($message,$desc='',$category = 'warning')
	{
		$message = is_array($message) ? Json::encode($message) : $message;
		$message = $desc ? $desc.'：'.$message : $message;
		Yii::info($message,$category);
	}
	
	/**
	 * 只有开发环境才会有的日志
	 * @param $message
	 * @param string $desc
	 * @param string $category
	 */
	public static function debugInfo($message,$desc='',$category = 'runtime')
	{
		if (YII_DEBUG) {
			$message = is_array($message) ? Json::encode($message) : $message;
			$message = $desc ? $desc.'：'.$message : $message;
			Yii::info($message,$category);
		}
	}
	
}